package br.cin.ufpe.corba.iiop;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

public class ReplyHeader {
	
	private long request_id;
	private ReplyStatusType reply_status;
	
	public long getRequestId() {
		return request_id;
	}
	
	public void setRequestId(long request_id) {
		this.request_id = request_id;
	}
	
	public ReplyStatusType getReplyStatus() {
		return reply_status;
	}
	
	public void setReplyStatus(ReplyStatusType reply_status) {
		this.reply_status = reply_status;
	}

	public void write(OutputStream out) throws IOException {
		DataOutputStream dos = new DataOutputStream(out);
		dos.writeLong(request_id);
		dos.writeByte(reply_status.ordinal());		
	}

	public static ReplyHeader read(InputStream in) throws IOException {
		DataInputStream dis = new DataInputStream(in);
		ReplyHeader result = new ReplyHeader();
		result.setRequestId(dis.readLong());
		result.setReplyStatus(ReplyStatusType.values()[dis.readByte()]);
		return result;
	}
	
}
